!!ARBvp1.0
# Simple program to show how to code up the default texture environment

# Program environment parameters:
# c[0].xyz = normalized light direction in object-space
#
# outputs diffuse illumination for color and perturbed position
#
ATTRIB iPos         = vertex.position;
ATTRIB iTex			= vertex.texcoord;
ATTRIB iNrm			= vertex.normal;
ATTRIB iCol			= vertex.color;

PARAM  offset		= program.local[0];

PARAM  	mvp[4]      = { state.matrix.mvp };
PARAM	mvinv[4]	= { state.matrix.modelview.invtrans };
PARAM  lightDir     = state.light[0].position;
PARAM  halfDir      = state.light[0].half;
PARAM  specExp      = state.material.shininess;
PARAM  ambientCol   = state.lightprod[0].ambient;
PARAM  diffuseCol   = state.lightprod[0].diffuse;
PARAM  specularCol  = state.lightprod[0].specular;
   
TEMP	tempColor;
TEMP	raised;
TEMP	eyeNrm;
TEMP	dots;

OUTPUT oPos        	= result.position;
OUTPUT oTex			= result.texcoord;
OUTPUT oCol			= result.color;

#
# TEXTURE - just copy from the source coords.
#
MOV		oTex, iTex;

#
# VERTEX POSITION - first move the vertex out along the scaled normal vector
# by an amount that comes from x-plane in program local 0.  This moves the
# clouds out from the planet surface.
#
MAD		raised, iNrm, offset, iPos;
#
# Then we transform it from world coords to clip coords - required for all vertex shaders.
#
DP4   	oPos.x, mvp[0], raised;	
DP4   	oPos.y, mvp[1], raised;
DP4   	oPos.z, mvp[2], raised;
DP4  	oPos.w, mvp[3], raised;

#
# LIGHTING - first we transform our normal from world-space to camera space.
#
DP3		eyeNrm.x, mvinv[0], iNrm;
DP3		eyeNrm.y, mvinv[1], iNrm;
DP3		eyeNrm.z, mvinv[2], iNrm;

# 
# What happens next is, well, weird - I got this from the ARB spec example.  Basically...
# First we calculate the dot products for diffuse and specular lighting, and put the
# specular exponent into w.  We then call the "LIT" op, which is a magic instruction that 
# transforms these dot products into the ambient, material, and specular lighting levels.
# 
# LIT is basically short-hand for a bunch of EXP calls, but it can do it in one opp and
# do some swizzling too.
#
DP3		dots.x, eyeNrm, lightDir;
DP3		dots.y, eyeNrm, halfDir;
MOV		dots.w, specExp.w;
LIT		dots, dots;
#
# Now we build up the color by multiplying the color contributions by the result of the LIT
# op.  Alpha comes right from the diffuse color, which would correspond to whatever we
# encoded with glColor.
#
MAD		tempColor, dots.y, diffuseCol, ambientCol;
MAD		oCol.xyz, dots.z, specularCol, tempColor;
MOV		oCol.w, iCol.w;

END
